package org.witsoft.dtx.config;

import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @author XiaoQing Lin
 * @date 2020-12-09 16:08
 */
public class DtxConfigurationSelector implements ImportSelector {

    @Override
    public String[] selectImports(AnnotationMetadata annotationMetadata) {
        AnnotationAttributes attributes = AnnotationAttributes.fromMap(annotationMetadata.getAnnotationAttributes(EnableDTX.class.getName(), false));
        boolean schedule = attributes.getBoolean("schedule");
        if (schedule) {
            return new String[]{
                    DtxBaseConfiguration.class.getName() ,
                    DtxScheduleConfiguration.class.getName()
            };
        }else {
            return new String[]{
                    DtxBaseConfiguration.class.getName()
            };
        }
    }
}
